package cn.tedu.mall.search.test.tree;

import java.util.Deque;
import java.util.LinkedList;

public class zhaibianli {
    public static void main(String[] args) {
        Node root = new Node(5);
        root.left = new Node(3);
        root.left.left = new Node(9);
        root.left.right = new Node(8);
        root.right = new Node(3);
        root.right.left = new Node(8);
        root.right.right = new Node(9);

        f(root);
    }

    private static void f(Node root) {
        Deque<Node> stack = new LinkedList();
        stack.push(root);

        while ( !stack.isEmpty()){
            Node n = stack.pop();
            System.out.println(n.value);
            if (n.left !=null) stack.push(n.left);
            if (n.right !=null) stack.push(n.right);
        }
    }

    static class Node {
        int value;
        Node left;
        Node right;

        Node(int value) {
            this.value = value;
        }
    }
}
